package cn.flyboy.mapper;

import java.util.List;

import cn.flyboy.entity.Answer;
import cn.flyboy.entity.Student;
import cn.flyboy.entity.Teacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface StudentMapper {
    @Select("select * from student where stu_exam=#{stu_exam} and stu_name=#{stu_name} and stu_id=#{stu_id}")
    Student selByStudent(Student student);

    @Select("select * from student where stu_id=#{param1} and stu_exam=#{param2}")
    Student selStudentByIdExam(String stuId, String stuExam);

    @Select("select * from student where stu_id=#{param1} and stu_ip=#{param2} and stu_exam=#{param3}")
    Student selByStudentIP(String stu_id, String stu_ip, String stu_exam);

    @Select("select s.stu_id,s.stu_name,s.stu_class,s.stu_exam,s.stu_ip,s.stu_submit from student s,exam e where s.stu_exam=e.e_name and s.stu_exam=#{param1} and e.e_teacher=#{param2}")
    List<Student> selAllStudents(String e_name, String e_teacher);

    @Select("select * from student where stu_exam=#{param2} and stu_id like CONCAT('%',#{param1,jdbcType=VARCHAR},'%') ")
    List<Student> selStudentById(String stu_id, String e_name);

    @Insert("insert into student(stu_id,stu_name,stu_class,stu_exam) values(#{stu_id},#{stu_name},#{stu_class},#{stu_exam})")
    int insStudent(Student student);

    @Select("select * from answer where stu_id=#{param1} and exam_name=#{param2}")
    List<Answer> selAllAnswerInfo(String stu_id, String exam_name);

    @Update("update student set stu_ip=null where stu_id=#{param1}")
    int updUnBind(String stu_id);

    @Update("update student set stu_ip=#{stu_ip} where stu_id=#{stu_id}")
    int updStuIp(Student stu);

    @Update("update student set stu_name=#{stu_name},stu_class=#{stu_class} where stu_username=#{stu_username}")
    int editStudent(Student student);

    @Update("update student set stu_submit=1 where stu_id=#{param1} and stu_exam=#{param2}")
    int editStudentOfSubmit(String stu_id, String stu_exam);

    @Delete("delete from student where stu_exam=#{param1}")
    int delStudentOfExam(String exam);

    @Delete("delete from student where stu_name=#{param1} and stu_exam=#{param2}")
    int delStudentExam(String stuName, String stuExam);
}
